package com.zph.dao;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.Part;
import javax.mail.Session;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import javax.mail.internet.MimeUtility;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFTable;
import org.apache.poi.xwpf.usermodel.XWPFTableCell;
import org.apache.poi.xwpf.usermodel.XWPFTableRow;
import org.jsoup.Jsoup;
import org.jsoup.safety.Whitelist;
import org.jsoup.select.Elements;
import org.junit.Test;
import org.pdfbox.pdfparser.PDFParser;
import org.pdfbox.pdmodel.PDDocument;

import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.parser.PdfReaderContentParser;
import com.itextpdf.text.pdf.parser.SimpleTextExtractionStrategy;
import com.itextpdf.text.pdf.parser.TextExtractionStrategy;
import com.zph.entity.Basic;
import com.zph.entity.CV;
import com.zph.entity.CVObject;
import com.zph.exception.FileOverSizeException;
import com.zzh.test.Base64;

public class ResumeToTxt {
	private static ParseResume PARSE = new ParseResume();
	private static ParseList PARSE_RECORD = new ParseList();
	private static ImportList PARSE_CONTACT = new ImportList();
	private static BufferedWriter out = null;
	private static String list_name = null;
	private static int totalNum = 1;
	private static int totalNumCount = 1;
	// private static String path = "F:\\简历解压\\Json\\";
	private static String path = "/data/zzh/Json/";

	public static void insertCV(int id, int ownerid, int companyid, IDatabaseDao dao) {
		CV cv = new CV();
		cv.setSource(1);
		cv.setUpdateTime(new Date());
		dao.insertCV(cv);
		int cvId = cv.getId();
		Map map = new HashMap<String, Integer>();
		map.put("candidateid", cvId);
		map.put("id", id);
		dao.updateCVFileCandidate(map);
		// cv.setId(cvId);
		cv.setCvFileId(id);
		cv.setCompanyId(companyid);
		cv.setOwnerId(ownerid);
		dao.updateCVById(cv);

		Basic basic = new Basic();
		basic.setOwnerid(ownerid);
		basic.setCompany_id(companyid);
		basic.setFileid(id);
		basic.setName("人才");
		basic.setCandidateId(cvId);
		basic.setPhotoId(0);
		basic.setProcessStage(0);
		dao.insertBasic(basic);
	}

	public static String extract(String filePath) {
		org.jsoup.nodes.Document doc = null;
		try {
			doc = Jsoup.parse(new File(filePath), "UTF-8");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		StringBuffer text = new StringBuffer();
		Elements trs = doc.select("table").select("tr");
		for (int i = 0; i < trs.size(); i++) {
			Elements tds = trs.get(i).select("td");
			for (int j = 0; j < tds.size(); j++) {
				String textTd = tds.get(j).text();
				text.append(textTd);
			}
		}
		return text.toString();
	}

	public static int parseWord(int id, int ownerid, int companyid, String fromFilepath, CVObject map,
			IDatabaseDao dao) {
		boolean isMht = false;
		boolean isHtml = false;
		/* 判断是否是伪word(.mht) */
		// 根据文件内容判断文件类型
		try {
			FileReader fr = new FileReader(fromFilepath);
			BufferedReader br = new BufferedReader(fr);
			String tmp = null;
			while ((tmp = br.readLine()) != null) {
				// mht
				if (tmp.indexOf("_9ed30801b0c180c69b3c5d74fede848e") != -1||tmp.indexOf("boundary") != -1) {
					isMht = true;
				} else if (tmp.indexOf("NextPart_01D28201.1DBED6F0") != -1) {
					isMht = true;
				} else if (tmp.indexOf("<table") != -1) {
					isHtml = true;
				}
			}

		} catch (IOException e) {
			e.printStackTrace();
		}

		System.out.println("parse word");
		int resultCode = 0;
		if (isMht) {
			parseMht(fromFilepath, map);
		} else if (isHtml) {
			parseHtm(0, 0, 0, fromFilepath, map, null);
		} else if (fromFilepath.endsWith(".doc")) {
			InputStream is = null;
			String text2003 = "";
			try {
				is = new FileInputStream(new File(fromFilepath));
				System.out.println("before");
				HWPFDocument doc = new HWPFDocument(is);
				System.out.println("after");
				text2003 = doc.getDocumentText();
				if (map != null) {
					PARSE.getSeparation(text2003, map);
				} else {
					PARSE.getSeparationBehind(id, ownerid, companyid, text2003, dao);
				}
			} catch (Exception e) {
				if (map != null) {
					// String textDoc = extract(fromFilepath);
					FileInputStream fis = null;
					InputStreamReader isr = null;
					BufferedReader br = null;
					String line = "";
					String result = "";
					int i = 0;
					while (i < 1) {
						try {
							fis = new FileInputStream(fromFilepath);
						} catch (FileNotFoundException e1) {
							e1.printStackTrace();
						}
						try {
							isr = new InputStreamReader(fis, "utf8");
						} catch (UnsupportedEncodingException e2) {
							e2.printStackTrace();
						}
						br = new BufferedReader(isr);
						try {
							while ((line = br.readLine()) != null) {
								result += line + "\r\n";
							}
						} catch (IOException e3) {
							// TODO Auto-generated catch block
							e3.printStackTrace();
						}
						if (result.contains("宋体")) {
							break;
						}
						result = "";
						try {
							fis = new FileInputStream(fromFilepath);
						} catch (FileNotFoundException e1) {
							e1.printStackTrace();
						}
						try {
							isr = new InputStreamReader(fis, "utf16");
						} catch (UnsupportedEncodingException e2) {
							e2.printStackTrace();
						}
						br = new BufferedReader(isr);
						try {
							while ((line = br.readLine()) != null) {
								result += line + "\r\n";
							}
						} catch (IOException e3) {
							// TODO Auto-generated catch block
							e3.printStackTrace();
						}
						if (result.contains("宋体")) {
							break;
						}
						result = "";
						try {
							fis = new FileInputStream(fromFilepath);
						} catch (FileNotFoundException e1) {
							e1.printStackTrace();
						}
						try {
							isr = new InputStreamReader(fis, "gbk");
						} catch (UnsupportedEncodingException e2) {
							e2.printStackTrace();
						}
						br = new BufferedReader(isr);
						try {
							while ((line = br.readLine()) != null) {
								result += line + "\r\n";
							}
						} catch (IOException e3) {
							// TODO Auto-generated catch block
							e3.printStackTrace();
						}
						if (result.contains("宋体")) {
							break;
						}
						result = "";
						try {
							fis = new FileInputStream(fromFilepath);
						} catch (FileNotFoundException e1) {
							e1.printStackTrace();
						}
						try {
							isr = new InputStreamReader(fis, "gb2312");
						} catch (UnsupportedEncodingException e2) {
							e2.printStackTrace();
						}
						br = new BufferedReader(isr);
						try {
							while ((line = br.readLine()) != null) {
								result += line + "\r\n";
							}
						} catch (IOException e1) {
							// TODO Auto-generated catch block
							e1.printStackTrace();
						}
						if (result.contains("宋体")) {
							break;
						}
						i++;
					}

					result = result.replaceAll("[\\t\\n\\r]", "");
					System.out.println(result);
					// result = result.substring(0,
					// Math.max(result.indexOf("<html>"), 0));
					result = result.replaceAll("</?[^>]+>", ""); // 剔出<html>的标签
					result = result.replaceAll("<a>\\s*|\t|\r|\n</a>", "");
					result = result.replaceAll("&nbsp;", "");
					result = result.replaceAll("&nbsp", "");
					try {
						PARSE.getSeparation(result, map);
					} catch (IOException e1) {
						e1.printStackTrace();
					}
				} else {
					try {
						// String textDoc = extract(fromFilepath);
						FileInputStream fis = null;
						InputStreamReader isr = null;
						BufferedReader br = null;
						String line = "";
						String result = "";
						int i = 0;
						while (i < 1) {
							try {
								fis = new FileInputStream(fromFilepath);
							} catch (FileNotFoundException e1) {
								e1.printStackTrace();
							}
							try {
								isr = new InputStreamReader(fis, "utf8");
							} catch (UnsupportedEncodingException e2) {
								e2.printStackTrace();
							}
							br = new BufferedReader(isr);
							while ((line = br.readLine()) != null) {
								result += line + "\r\n";
							}
							if (result.contains("宋体")) {
								break;
							}
							result = "";
							try {
								fis = new FileInputStream(fromFilepath);
							} catch (FileNotFoundException e1) {
								e1.printStackTrace();
							}
							try {
								isr = new InputStreamReader(fis, "utf16");
							} catch (UnsupportedEncodingException e2) {
								e2.printStackTrace();
							}
							br = new BufferedReader(isr);
							while ((line = br.readLine()) != null) {
								result += line + "\r\n";
							}
							if (result.contains("宋体")) {
								break;
							}
							result = "";
							try {
								fis = new FileInputStream(fromFilepath);
							} catch (FileNotFoundException e1) {
								e1.printStackTrace();
							}
							try {
								isr = new InputStreamReader(fis, "gbk");
							} catch (UnsupportedEncodingException e2) {
								e2.printStackTrace();
							}
							br = new BufferedReader(isr);
							while ((line = br.readLine()) != null) {
								result += line + "\r\n";
							}
							if (result.contains("宋体")) {
								break;
							}
							result = "";
							try {
								fis = new FileInputStream(fromFilepath);
							} catch (FileNotFoundException e1) {
								e1.printStackTrace();
							}
							try {
								isr = new InputStreamReader(fis, "gb2312");
							} catch (UnsupportedEncodingException e2) {
								e2.printStackTrace();
							}
							br = new BufferedReader(isr);
							while ((line = br.readLine()) != null) {
								result += line + "\r\n";
							}
							if (result.contains("宋体")) {
								break;
							}
							i++;
						}

						result = result.replaceAll("[\\t\\n\\r]", "");
						System.out.println(result);
						// result = result.substring(0,
						// Math.max(result.indexOf("<html>"), 0));
						result = result.replaceAll("</?[^>]+>", ""); // 剔出<html>的标签
						result = result.replaceAll("<a>\\s*|\t|\r|\n</a>", "");
						result = result.replaceAll("&nbsp;", "");
						result = result.replaceAll("&nbsp", "");
						PARSE.getSeparationBehind(id, ownerid, companyid, result, dao);
					} catch (Exception e2) {
						insertCV(id, ownerid, companyid, dao);
						resultCode = 1;
					}
					System.out.println("读取word2003异常");
				}
				e.printStackTrace();
			} finally {
				if (is != null) {
					try {
						is.close();
						is = null;
					} catch (IOException e) {
						resultCode = 1;
						e.printStackTrace();
					}
				}
			}
		} else if (fromFilepath.endsWith(".docx")) {
			StringBuilder text2007 = new StringBuilder();
			InputStream is = null;
			XWPFDocument doc = null;
			try {
				is = new FileInputStream(fromFilepath);
				doc = new XWPFDocument(is);
				List list = doc.getBodyElements();
				List<XWPFTableRow> rows;
				List<XWPFTableCell> cells;
				for (int i = 0; i < list.size(); i++) {
					if (list.get(i) instanceof XWPFParagraph) {
						XWPFParagraph para = (XWPFParagraph) (list.get(i));
						text2007.append(para.getText() + "\n");
					}
					if (list.get(i) instanceof XWPFTable) {
						XWPFTable table = (XWPFTable) (list.get(i));
						rows = table.getRows();
						for (XWPFTableRow row : rows) {
							// 获取行对应的单元格
							cells = row.getTableCells();
							for (XWPFTableCell cell : cells) {
								text2007.append(cell.getText() + "\n");
							}
						}
					}
				}
				if (map != null) {
					PARSE.getSeparation(text2007.toString(), map);
				} else {
					PARSE.getSeparationBehind(id, ownerid, companyid, text2007.toString(), dao);
				}
			} catch (Exception e) {
				try {
					// String textDoc = extract(fromFilepath);
					FileInputStream fis = null;
					InputStreamReader isr = null;
					BufferedReader br = null;
					String line = "";
					String result = "";
					int i = 0;
					while (i < 1) {
						try {
							fis = new FileInputStream(fromFilepath);
						} catch (FileNotFoundException e1) {
							e1.printStackTrace();
						}
						try {
							isr = new InputStreamReader(fis, "utf8");
						} catch (UnsupportedEncodingException e2) {
							e2.printStackTrace();
						}
						br = new BufferedReader(isr);
						while ((line = br.readLine()) != null) {
							result += line + "\r\n";
						}
						if (result.contains("宋体")) {
							break;
						}
						result = "";
						try {
							fis = new FileInputStream(fromFilepath);
						} catch (FileNotFoundException e1) {
							e1.printStackTrace();
						}
						try {
							isr = new InputStreamReader(fis, "utf16");
						} catch (UnsupportedEncodingException e2) {
							e2.printStackTrace();
						}
						br = new BufferedReader(isr);
						while ((line = br.readLine()) != null) {
							result += line + "\r\n";
						}
						if (result.contains("宋体")) {
							break;
						}
						result = "";
						try {
							fis = new FileInputStream(fromFilepath);
						} catch (FileNotFoundException e1) {
							e1.printStackTrace();
						}
						try {
							isr = new InputStreamReader(fis, "gbk");
						} catch (UnsupportedEncodingException e2) {
							e2.printStackTrace();
						}
						br = new BufferedReader(isr);
						while ((line = br.readLine()) != null) {
							result += line + "\r\n";
						}
						if (result.contains("宋体")) {
							break;
						}
						result = "";
						try {
							fis = new FileInputStream(fromFilepath);
						} catch (FileNotFoundException e1) {
							e1.printStackTrace();
						}
						try {
							isr = new InputStreamReader(fis, "gb2312");
						} catch (UnsupportedEncodingException e2) {
							e2.printStackTrace();
						}
						br = new BufferedReader(isr);
						while ((line = br.readLine()) != null) {
							result += line + "\r\n";
						}
						if (result.contains("宋体")) {
							break;
						}
						i++;
					}

					result = result.replaceAll("[\\t\\n\\r]", "");
					System.out.println(result);
					// result = result.substring(0,
					// Math.max(result.indexOf("<html>"), 0));
					result = result.replaceAll("</?[^>]+>", ""); // 剔出<html>的标签
					result = result.replaceAll("<a>\\s*|\t|\r|\n</a>", "");
					result = result.replaceAll("&nbsp;", "");
					result = result.replaceAll("&nbsp", "");
					PARSE.getSeparationBehind(id, ownerid, companyid, result, dao);
				} catch (Exception e2) {
					insertCV(id, ownerid, companyid, dao);
					resultCode = 1;
				}
				e.printStackTrace();
			} finally {
				if (is != null) {
					try {
						is.close();
						is = null;
					} catch (IOException e) {
						e.printStackTrace();
					}
				}
			}
		}
		return resultCode;
	}

	public static int parseExcel(int id, int ownerid, int companyid, String fromFilepath, CVObject map,
			IDatabaseDao dao) {
		int resultCode = 0;
		String sheetName;
		int rowCount;
		String tmp = "";
		InputStream inStream = null;
		StringBuilder text = new StringBuilder();
		try {
			inStream = new FileInputStream(fromFilepath);
			if (fromFilepath.endsWith("xls")) {
				HSSFWorkbook workbook = null;
				workbook = new HSSFWorkbook(inStream);
				for (int numSheet = 0, len = workbook.getNumberOfSheets(); numSheet < len; numSheet++) {
					HSSFSheet sheet = workbook.getSheetAt(numSheet);
					if (sheet == null) {
						continue;
					}
					sheetName = workbook.getSheetName(numSheet);
					rowCount = sheet.getLastRowNum();
					for (int rowid = 0; rowid <= rowCount; rowid++) {
						HSSFRow row = sheet.getRow(rowid);
						if (row == null) {
							continue;
						}
						int cellCount = row.getLastCellNum();
						for (int cellid = 0; cellid < cellCount; cellid++) {
							HSSFCell cell = row.getCell(cellid);
							tmp = "";
							if (cell != null) {
								cell.setCellType(HSSFCell.CELL_TYPE_STRING);
								tmp = getValue(cell);
							}
							text.append(tmp);
						}
					}
				}
				if (map != null) {
					PARSE.getSeparation(text.toString(), map);
				} else {
					PARSE.getSeparationBehind(id, ownerid, companyid, text.toString(), dao);
				}
			} else {
				XSSFWorkbook workbook = null;
				workbook = new XSSFWorkbook(inStream);
				for (int numSheet = 0, len = workbook.getNumberOfSheets(); numSheet < len; numSheet++) {
					XSSFSheet sheet = workbook.getSheetAt(numSheet);
					if (sheet == null) {
						continue;
					}
					rowCount = sheet.getLastRowNum();
					for (int rowid = 0; rowid <= rowCount; rowid++) {
						XSSFRow row = sheet.getRow(rowid);
						if (row == null) {
							continue;
						}
						int cellCount = row.getLastCellNum();
						for (int cellid = 0; cellid < cellCount; cellid++) {
							XSSFCell cell = row.getCell(cellid);
							tmp = "";
							if (cell != null) {
								cell.setCellType(XSSFCell.CELL_TYPE_STRING);
								tmp = getValue1(cell);
							}
							text.append(tmp);
						}
					}
				}
			}
			if (map != null) {
				PARSE.getSeparation(text.toString(), map);
			} else {
				PARSE.getSeparationBehind(id, ownerid, companyid, text.toString(), dao);
			}
		} catch (FileNotFoundException e) {
			insertCV(id, ownerid, companyid, dao);
			resultCode = 1;
			e.printStackTrace();
		} catch (UnsupportedEncodingException e) {
			insertCV(id, ownerid, companyid, dao);
			resultCode = 1;
			e.printStackTrace();
		} catch (IOException e) {
			insertCV(id, ownerid, companyid, dao);
			resultCode = 1;
			e.printStackTrace();
		} finally {
			if (inStream != null) {
				try {
					inStream.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
				inStream = null;
			}
		}
		return resultCode;
	}

	// 解析寻访记录
	public static int parseExcelRecord(int id, String fromFilepath, CVObject map, IDatabaseDao dao) {
		System.out.println("=======parseExcelRecord========");
		int resultCode = 0;
		String sheetName;
		int rowCount;
		String tmp = "";
		InputStream inStream = null;
		StringBuilder text = new StringBuilder();
		try {
			PARSE_RECORD.parseBehind(id, fromFilepath, dao);
		} finally {
			if (inStream != null) {
				try {
					inStream.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
				inStream = null;
			}
		}
		return resultCode;
	}

	// 解析联系人
	public static int parseExcelContact(int id, int userId, int companyId, String fromFilepath, CVObject map,
			IDatabaseDao dao) {
		System.out.println("=======parseExcelcontact========");
		int resultCode = 0;
		String sheetName;
		int rowCount;
		String tmp = "";
		InputStream inStream = null;
		StringBuilder text = new StringBuilder();
		try {
			PARSE_CONTACT.parseBehind(id, userId, companyId, fromFilepath, dao);
		} finally {
			if (inStream != null) {
				try {
					inStream.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
				inStream = null;
			}
		}
		return resultCode;
	}

	// 解析联系人
	public static int parseCSVContact(int id, int userId, int companyId, String fromFilepath, CVObject map,
			IDatabaseDao dao) throws IOException {
		System.out.println("=======parseCSVcontact========");
		int resultCode = 0;
		String sheetName;
		int rowCount;
		String tmp = "";
		InputStream inStream = null;
		StringBuilder text = new StringBuilder();
		try {
			PARSE_CONTACT.parseCSVBehind(id, userId, companyId, fromFilepath, dao);
		} finally {
			if (inStream != null) {
				try {
					inStream.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
				inStream = null;
			}
		}
		return resultCode;
	}

	@SuppressWarnings("static-access")
	private static String getValue(HSSFCell hssfCell) {
		if (hssfCell.getCellType() == hssfCell.CELL_TYPE_BOOLEAN) {
			return String.valueOf(hssfCell.getBooleanCellValue());
		} else if (hssfCell.getCellType() == hssfCell.CELL_TYPE_NUMERIC) {
			return String.valueOf(hssfCell.getNumericCellValue());
		} else {
			return String.valueOf(hssfCell.getStringCellValue());
		}
	}

	@SuppressWarnings("static-access")
	private static String getValue1(XSSFCell xssfCell) {
		if (xssfCell.getCellType() == XSSFCell.CELL_TYPE_BOOLEAN) {
			return String.valueOf(xssfCell.getBooleanCellValue());
		} else if (xssfCell.getCellType() == XSSFCell.CELL_TYPE_NUMERIC) {
			return String.valueOf(xssfCell.getNumericCellValue());
		} else {
			return String.valueOf(xssfCell.getStringCellValue());
		}
	}

	public static int parsePdf(int id, int ownerid, int companyid, String fromFilepath, CVObject map,
			IDatabaseDao dao) {
		int resultCode = 0;
		String text = "";
		FileInputStream is = null;
		PDDocument document = null;
		PDFParser parser = null;
		try {
			/*
			 * is = new FileInputStream(fromFilepath); parser = new
			 * PDFParser(is); parser.parse(); document = parser.getPDDocument();
			 * PDFTextStripper stripper = new PDFTextStripper(); text =
			 * stripper.getText(document); //
			 */
			PdfReader reader = new PdfReader(fromFilepath);
			PdfReaderContentParser parser1 = new PdfReaderContentParser(reader);
			StringBuffer buff = new StringBuffer();
			TextExtractionStrategy strategy;
			for (int i = 1; i <= reader.getNumberOfPages(); i++) {
				strategy = parser1.processContent(i, new SimpleTextExtractionStrategy());
				buff.append(strategy.getResultantText());
			}
			text = buff.toString();
			if (map != null) {
				// 线上解析接口
				PARSE.getSeparation(text, map);
			} else {
				// 线下测试接口
				PARSE.getSeparationBehind(id, ownerid, companyid, text, dao);
			}
		} catch (FileNotFoundException e) {
			resultCode = 1;
			e.printStackTrace();
		} catch (IOException e) {
			resultCode = 1;
			e.printStackTrace();
		} finally {
			if (is != null) {
				try {
					is.close();
					is = null;
				} catch (IOException e) {
					resultCode = 1;
					e.printStackTrace();
				}
			}
			if (document != null) {
				try {
					document.close();
					document = null;
				} catch (IOException e) {
					resultCode = 1;
					e.printStackTrace();
				}
			}
		}
		return resultCode;
	}

	private static void parseEml(int id, int ownerid, int companyid, String fromFilepath, CVObject map,
			IDatabaseDao dao) {
		try {
			parserFile(fromFilepath);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static void parserFile(String emlPath) throws Exception {
		Properties props = new Properties();
		Session session = Session.getDefaultInstance(props, null);
		InputStream inMsg;
		inMsg = new FileInputStream(emlPath);
		Message msg = new MimeMessage(session, inMsg);
		parseEml(msg);
	}

	private static void parseEml(Message msg) throws Exception {
		Object o = msg.getContent();
		if (o instanceof Multipart) {
			Multipart multipart = (Multipart) o;
			reMultipart(multipart);
		} else if (o instanceof Part) {
			Part part = (Part) o;
			rePart(part);
		} else {
			// System.out.println("类型" + msg.getContentType());
			// System.out.println("内容" + msg.getContent());
		}
	}

	/**
	 * @param part
	 *            解析内容
	 * @throws Exception
	 */
	private static void rePart(Part part) throws Exception {
		String tempPath = "F:\\toresume\\ss\\";
		{

			if (part.getDisposition() != null) {

				String strFileNmae = part.getFileName();
				if (!strFileNmae.isEmpty()) {
					// MimeUtility.decodeText解决附件名乱码问题
					strFileNmae = MimeUtility.decodeText(strFileNmae);
					// System.out.println("发现附件: "+ strFileNmae);
					InputStream in = part.getInputStream();// 打开附件的输入流
					// 读取附件字节并存储到文件中
					java.io.FileOutputStream out = new FileOutputStream(tempPath + strFileNmae);
					int data;
					while ((data = in.read()) != -1) {
						out.write(data);
					}
					in.close();
					out.close();
					CVObject map = new CVObject();
					if (strFileNmae.endsWith("doc") || strFileNmae.endsWith("docx")) {
						parseWord(0, 0, 0, tempPath + strFileNmae, map, null);
					} else if (strFileNmae.endsWith("xls") || strFileNmae.endsWith("xlsx")) {
						parseExcel(0, 0, 0, tempPath + strFileNmae, map, null);
					} else if (strFileNmae.endsWith("pdf")) {
						parsePdf(0, 0, 0, tempPath + strFileNmae, map, null);
					} else if (strFileNmae.endsWith("htm") || strFileNmae.endsWith("html")) {
						System.out.println("tempPath + strFileNmae" + tempPath + strFileNmae);
						parseHtm(0, 0, 0, tempPath + strFileNmae, map, null);
					} else {
						String text = readFileByLines(tempPath + strFileNmae);
					}
				}
			}
		}
	}

	/**
	 * 以行为单位读取文件，常用于读面向行的格式化文件
	 */
	public static String readFileByLines(String fileName) {
		StringBuilder sb = new StringBuilder();
		File file = new File(fileName);
		BufferedReader reader = null;
		try {
			reader = new BufferedReader(new FileReader(file));
			String tempString = null;
			int line = 1;
			// 一次读入一行，直到读入null为文件结束
			while ((tempString = reader.readLine()) != null) {
				// 显示行号
				sb.append(tempString);
				line++;
			}
			reader.close();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (reader != null) {
				try {
					reader.close();
				} catch (IOException e1) {
				}
			}
		}
		return sb.toString();
	}

	/**
	 * @param multipart
	 *            // 接卸包裹（含所有邮件内容(包裹+正文+附件)）
	 * @throws Exception
	 */
	private static void reMultipart(Multipart multipart) throws Exception {
		// 依次处理各个部分
		for (int j = 0, n = multipart.getCount(); j < n; j++) {
			Part part = multipart.getBodyPart(j);// 解包, 取出 MultiPart的各个部分,
			// 每部分可能是邮件内容,
			// 也可能是另一个小包裹(MultipPart)
			// 判断此包裹内容是不是一个小包裹, 一般这一部分是 正文 Content-Type: multipart/alternative
			if (part.getContent() instanceof Multipart) {
				Multipart p = (Multipart) part.getContent();// 转成小包裹
				// 递归迭代
				reMultipart(p);
			} else {
				rePart(part);
			}
		}
	}

	/*
	 * @Test public void test(){ String server_pathname =
	 * "C:/Users/gongcaichun/Documents/Tencent Files/1247979854/FileRecv/刘先生_2015智联招聘.html"
	 * ; parseHtm(0, 0, 0, server_pathname, null, null); }
	 */

	public static int parseHtm(int id, int ownerid, int companyid, String fromFilepath, CVObject map,
			IDatabaseDao dao) {
		int resultCode = 0;

		/* 张振华 html简历解析 */

		org.jsoup.nodes.Document doc = null;
		Elements eles = null;
		try {

			doc = Jsoup.parse(new File(fromFilepath), get_charset(fromFilepath));
			// doc = Jsoup.parse(new File(fromFilepath), "UTF-8");
			// 原始未动，当非定模板时

			// StringBean sb = new StringBean();
			// sb.setLinks(false);
			// sb.setReplaceNonBreakingSpaces(true);
			// sb.setCollapse(true);
			// sb.setURL(fromFilepath); getFormateTxt
			// String text = sb.getStrings();
			String text = getFormateTxt(doc.toString());

			if (map != null) {
				PARSE.getSeparation(text, map);
			} else {
				PARSE.getSeparationBehind(id, ownerid, companyid, text, dao);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}

		return resultCode;

	}

	public static void main(String[] args) {
		CVObject map = new CVObject();
		// String filename ="C:/Users/gongcaichun/Desktop/wwww刘先生_2015.html";
		// parseResumeNow(map,"F:\\resumetxt\\resume\\resume\\简历\\"+"智联招聘_任迎_UI设计师_中文_20150806_84747910.doc");
		// parseResumeNow(map,"C:/Users/gongcaichun/Desktop/"+"Java实习生_张飞飞_吉林大学.doc");
		// parseResumeNow(map,"E:\\ran.doc");
		// parseResumeNow(map,filename);
		// System.out.println("-----------------------"+JSONUtil.ObjectToJSON(map));
		System.out.println("============ start parse ============");
		parseResumeBehind();
	}

	public static void parseResumeNow(CVObject map, String filepath)  { 
		
		
		
		
		//解析文件大小设定
		File file = new File(filepath);
		System.out.println(file.length()); 
		if(file.exists()){ //&&file.length()<500000  
			//存储文件路径 
			map.setFilePath(filepath); 
			if (filepath.endsWith("doc") || filepath.endsWith("docx")) {
				parseWord(0, 0, 0, filepath, map, null); 
			} else if (filepath.endsWith("xls") || filepath.endsWith("xlsx")) {
				parseExcel(0, 0, 0, filepath, map, null); 
			} else if (filepath.endsWith("pdf")) {
				parsePdf(0, 0, 0, filepath, map, null); 
			} else if (filepath.endsWith("htm") || filepath.endsWith("html")) { 
				parseHtm(0, 0, 0, filepath, map, null);

			} else if (filepath.endsWith("eml")) {
				parseEml(0, 0, 0, filepath, map, null);
			} else if (filepath.endsWith("mht")) {
				parseMht(filepath, map);

			} else if (filepath.endsWith("txt")) {
				parseTxt(filepath, map); 
			} 
		}else{ 
//			throw new FileOverSizeException(file.length()+"<--文件过大-->"+file.getAbsolutePath());
			throw new FileOverSizeException(filepath+" 文件不存在,请检查路径是否正确");
		}
		
		
	}

	private static void parseMht(String filepath, CVObject map) { 
		try {
			 System.out.println("mht");
			InputStream fis = new FileInputStream(filepath);
			Session mailSession = Session.getDefaultInstance(System.getProperties(), null);
			MimeMessage msg = new MimeMessage(mailSession, fis);
			Object content = msg.getContent();
			if (content instanceof Multipart) {
				MimeMultipart mp = (MimeMultipart) content;
				MimeBodyPart bp1 = (MimeBodyPart) mp.getBodyPart(0);

				// 获取mht文件内容代码的编码
				String strEncodng = getEncoding(bp1);
				
				// 获取mht文件的内容
				String html = getHtmlText(bp1, strEncodng);

				if (html == null)
					return;
				// strText = strText.replaceAll("<[\\/]{0,1}br>", "\\n");

				// org.jsoup.nodes.Document doc = Jsoup.parse(strText);

				// 格式化html文本 text
				String text = getFormateTxt(html);
				// 去除&nbsp;
				text = text.replace("&nbsp;", " ");
				PARSE.getSeparation(text, map);
			}
		} catch (NullPointerException e) {

		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	private static String getFormateTxt(String html) {

		html = html.replace(">", ">\n");
		String text = Jsoup.clean(html, "", Whitelist.none(),
				new org.jsoup.nodes.Document.OutputSettings().prettyPrint(false));
		String text2 = "";
		for (String str : text.split("\n")) {
			if (str != null) {
				str = replaceTab(str);
				if (!str.trim().equals("")) {
					str = str.replace("&nbsp;", " ");
					text2 += str + "\n";
				}

			}

		}
		// System.out.println(text2);
		return text2;
	}

	// 去除制表符
	public static String replaceTab(String str) {
		String dest = "";
		try {
			if (str != null) { // \\s*|\t|\r|\n
				Pattern p = Pattern.compile("\\s*|\t|\r");
				Matcher m = p.matcher(str);
				dest = m.replaceAll("");
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return dest;
	}

	private static String getHtmlText(MimeBodyPart bp, String strEncoding) {
		InputStream textStream = null;
		BufferedInputStream buff = null;
		BufferedReader br = null;
		Reader r = null;
		try {
			textStream = bp.getInputStream();
			buff = new BufferedInputStream(textStream);

			if (strEncoding == null || strEncoding == "" || strEncoding.equals(""))
				r = new InputStreamReader(buff,"gbk");
			else
				r = new InputStreamReader(buff, strEncoding);

			br = new BufferedReader(r);
			StringBuffer strHtml = new StringBuffer("");
			String strLine = null;
			while ((strLine = br.readLine()) != null) {
				strHtml.append(strLine + "\r\n");
			}
			br.close();
			r.close();
			textStream.close();
			return strHtml.toString();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				if (br != null)
					br.close();
				if (buff != null)
					buff.close();
				if (textStream != null)
					textStream.close();
			} catch (Exception e) {
			}
		}
		return null;
	}
	/**
	 * 一次获取编码
	 */
	private static String getEncoding(MimeBodyPart bp) {
		if (bp == null) {
			return null;
		}
		try {
			Enumeration list = bp.getAllHeaders();
			while (list.hasMoreElements()) {
				javax.mail.Header head = (javax.mail.Header) list.nextElement();
				if (head.getName().equalsIgnoreCase("Content-Type")) {
					String strType = head.getValue();
					int pos = strType.indexOf("charset=");
					if (pos >= 0) {
						String strEncoding = strType.substring(pos + 8, strType.length());
						if (strEncoding.startsWith("\"") || strEncoding.startsWith("\'")) {
							strEncoding = strEncoding.substring(1, strEncoding.length());
						}
						if (strEncoding.endsWith("\"") || strEncoding.endsWith("\'")) {
							strEncoding = strEncoding.substring(0, strEncoding.length() - 1);
						}
						if (strEncoding.toLowerCase().compareTo("gb2312") == 0) {
							strEncoding = "gbk";
						}
						return strEncoding;
					}
				}
			}
		} catch (MessagingException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	 
	private static void parseTxt(String filepath, CVObject map) {
		// 解析txt文件
		String text = "", tmp;
		try { 
			System.out.println("txt");
			InputStream in = new FileInputStream(filepath);
			Reader reader = new InputStreamReader(in, get_charset(filepath));
			BufferedReader br = new BufferedReader(reader);

			while ((tmp = br.readLine()) != null) {
				text += tmp + " \n";
			}
			String base64=Base64.getBase64(text);
			System.out.println(base64); 
			// 线上解析接口
			PARSE.getSeparation(text, map);

		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	@Test
	public void test002() {
		try {
			// getCharset("E:/2015年购买/2011/9/第1356份简历.htm");
			System.out.println(get_charset("G:\\数据库裤子综合\\2000w如家开房txt两千万数据包\\两-千-万-数据包\\2-1.txt"));
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	/**
	 * 更加精准的文本编码识别
	 */
	public static String get_charset(String filepath) {
		String charset = "GBK";
		byte[] first3Bytes = new byte[3];
		try {
			boolean checked = false;
			File file = new File(filepath);
			BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
			bis.mark(0);
			int read = bis.read(first3Bytes, 0, 3);
			if (read == -1)
				return charset;
			if (first3Bytes[0] == (byte) 0xFF && first3Bytes[1] == (byte) 0xFE) {
				charset = "UTF-16LE";
				checked = true;
			} else if (first3Bytes[0] == (byte) 0xFE && first3Bytes[1] == (byte) 0xFF) {
				charset = "UTF-16BE";
				checked = true;
			} else if (first3Bytes[0] == (byte) 0xEF && first3Bytes[1] == (byte) 0xBB
					&& first3Bytes[2] == (byte) 0xBF) {
				charset = "UTF-8";
				checked = true;
			}
			bis.reset();
			if (!checked) {
				// int len = 0;
				int loc = 0;

				while ((read = bis.read()) != -1) {
					loc++;
					if (read >= 0xF0)
						break;
					if (0x80 <= read && read <= 0xBF) // 单独出现BF以下的，也算是GBK
						break;
					if (0xC0 <= read && read <= 0xDF) {
						read = bis.read();
						if (0x80 <= read && read <= 0xBF) // 双字节 (0xC0 - 0xDF)
															// (0x80
															// - 0xBF),也可能在GB编码内
							continue;
						else
							break;
					} else if (0xE0 <= read && read <= 0xEF) {// 也有可能出错，但是几率较小
						read = bis.read();
						if (0x80 <= read && read <= 0xBF) {
							read = bis.read();
							if (0x80 <= read && read <= 0xBF) {
								charset = "UTF-8";
								break;
							} else
								break;
						} else
							break;
					}
				}
				// System.out.println( loc + " " + Integer.toHexString( read )
				// );
			}

			bis.close();
		} catch (Exception e) {
			e.printStackTrace();
		}

		return charset;
	}

	/* 获取文本的编码格式 */
	public static String getCharset(String fileName) throws IOException {

		BufferedInputStream bin = new BufferedInputStream(new FileInputStream(fileName));
		int p = (bin.read() << 8) + bin.read();
		// System.out.println(bin.read() << 8);
		// System.out.println(bin.read());
		// System.out.println(p);
		// System.out.println("0xefbb");
		String code = null;

		switch (p) {
		case 0xefbb:
			code = "UTF-8";
			break;
		case 0xfffe:
			code = "Unicode";
			break;
		case 0xfeff:
			code = "UTF-16BE";
			break;
		default:
			code = "GBK";
		}
		System.out.println(code);
		return code;
	}

 
	public static void parseResumeBehind() {
		System.out.println("parseResumeBehind");

		int id = 0;
		String server_pathname = "";
		String original_filename = "";
		int ownerid = 0;
		int companyid = 0;
		int count = 0;
		String resource = "MyBatis-Configuration.xml";
		Reader reader = null;
		try {
			reader = Resources.getResourceAsReader(resource);
		} catch (IOException e) {
			e.printStackTrace();
		}
		SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
		SqlSessionFactory factory = builder.build(reader);
		/*
		 * try { out = new BufferedWriter(new OutputStreamWriter(new
		 * FileOutputStream(path + "resume" + totalNumCount + ".txt", true))); }
		 * catch (FileNotFoundException e1) { // TODO Auto-generated catch block
		 * e1.printStackTrace(); }
		 */

		while (true) {
			/*
			 * if(totalNum % 10 == 0) { totalNumCount++; System.out.println(
			 * "totalNum = " + totalNum); System.out.println("totalNumCount = "
			 * + totalNumCount); System.out.println("path = " + path + "resume"
			 * + totalNumCount + ".txt"); //totalNum = 0; try { out = new
			 * BufferedWriter(new OutputStreamWriter(new FileOutputStream(path +
			 * "resume" + totalNumCount + ".txt", true))); } catch
			 * (FileNotFoundException e) { // TODO Auto-generated catch block
			 * e.printStackTrace(); } }
			 */
			/// *
			// 解析简历
			SqlSession session = factory.openSession();
			IDatabaseDao dao = session.getMapper(IDatabaseDao.class);
			System.out.println("count" + count);
			List<Map> files = dao.queryCVFile();
			// List<Map> files1 = dao.queryCVFile1();
			if (files != null) {
				Iterator<Map> iter = files.iterator();
				// Iterator<Map> iter1 = files1.iterator();
				while (iter.hasNext()) {
					if (totalNum % 100000 == 1) {
						totalNumCount++;
						System.out.println("totalNum = " + totalNum);
						System.out.println("totalNumCount = " + totalNumCount);
						System.out.println("path = " + path + "resume" + totalNumCount + ".txt");
						// totalNum = 0;
						try {
							out = new BufferedWriter(new OutputStreamWriter(
									new FileOutputStream(path + "resume" + totalNumCount + ".txt", true)));
						} catch (FileNotFoundException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
					} else {
						try {
							out = new BufferedWriter(new OutputStreamWriter(
									new FileOutputStream(path + "resume" + totalNumCount + ".txt", true)));
						} catch (FileNotFoundException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
					}
					System.out.print(path);
					// System.exit(0);
					CVObject map = new CVObject();
					count++;
					Map u = iter.next();
					id = Integer.parseInt(u.get("id").toString());
					server_pathname = u.get("server_pathname").toString();
					System.out.println("server_pathname = " + server_pathname);
					// original_filename =
					// u.get("original_filename").toString();
					// ownerid = Integer.parseInt(u.get("ownerid").toString());
					// server_pathname = server_pathname + File.separator +
					// original_filename;
					// companyid = dao.queryCompanyId(ownerid);

					// System.out.println("----------------------------------companyid"+companyid);
					if (server_pathname.endsWith("doc") || server_pathname.endsWith("docx")
							|| server_pathname.endsWith("DOC") || server_pathname.endsWith("DOCX")
							|| server_pathname.endsWith("Doc") || server_pathname.endsWith("Docx")) {
						System.out.println("if doc");
						// parseWord(id,ownerid,companyid,server_pathname,map,dao);
						parseWord(0, 0, 0, server_pathname, map, null);
					} else if (server_pathname.endsWith("xls") || server_pathname.endsWith("xlsx")
							|| server_pathname.endsWith("XLS") || server_pathname.endsWith("XLSX")
							|| server_pathname.endsWith("Xls") || server_pathname.endsWith("Xlsx")) {
						System.out.println("if xls");
						// parseExcel(id,ownerid,companyid,server_pathname,map,dao);
						parseExcel(0, 0, 0, server_pathname, map, null);
					} else if (server_pathname.endsWith("pdf") || server_pathname.endsWith("Pdf")
							|| server_pathname.endsWith("PDF")) {
						System.out.println("if pdf");
						// parsePdf(id,ownerid,companyid,server_pathname,map,dao);
						parsePdf(0, 0, 0, server_pathname, map, null);
					} else if (server_pathname.endsWith("htm") || server_pathname.endsWith("html")
							|| server_pathname.endsWith("HTM") || server_pathname.endsWith("HTML")
							|| server_pathname.endsWith("Htm") || server_pathname.endsWith("Html")) {
						System.out.println("if html");
						// parseHtm(id,ownerid,companyid,server_pathname,map,dao);
						parseHtm(0, 0, 0, server_pathname, map, null);
					} else if (server_pathname.endsWith("eml") || server_pathname.endsWith("EML")
							|| server_pathname.endsWith("Eml")) {
						System.out.println("if eml");
						// parseEml(id,ownerid,companyid,server_pathname,map,dao);
						parseEml(0, 0, 0, server_pathname, map, null);
					}
					if (count % 1000 == 0) {
						session.commit();
						count = 0;
					}

					try {
						System.out.println("================= write ==================");
						out.write(JSONUtil.ObjectToJSON(map) + "\r\n\r\n\r\n\r\n");
						out.close();
						totalNum++;
					} catch (IOException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					System.out.println("-----------------------" + JSONUtil.ObjectToJSON(map));
					dao.updateCVFileFlag(id);
				}
			}
			session.commit();
			try {
				Thread.sleep(10000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			} finally {
				session.close();
				session = null;
			}
			// */
			/*
			 * try { //out.close(); } catch (IOException e) { // TODO
			 * Auto-generated catch block e.printStackTrace(); }
			 */
		}
		// out.close();
	}

	// 解析寻访记录
	public static void parseRecordBehind() {
		// 解析寻访记录
		int id = 0;
		String server_pathname = "";
		String original_filename = "";
		int ownerid = 0;
		int companyid = 0;
		int count = 0;
		String resource = "MyBatis-Configuration.xml";
		Reader reader = null;
		try {
			reader = Resources.getResourceAsReader(resource);
		} catch (IOException e) {
			e.printStackTrace();
		}
		SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
		SqlSessionFactory factory = builder.build(reader);
		while (true) {
			SqlSession session_record = factory.openSession();
			IDatabaseDao dao_record = session_record.getMapper(IDatabaseDao.class);
			// System.out.println("count"+count);
			List<Map> files_record1 = dao_record.queryRecord1();
			List<Map> files_record2 = dao_record.queryRecord2();
			if (files_record1 != null && files_record2 != null) {
				Iterator<Map> iter1 = files_record1.iterator();
				Iterator<Map> iter2 = files_record2.iterator();
				while (iter1.hasNext() && iter2.hasNext()) {
					count++;
					Map u1 = iter1.next();
					Map u2 = iter2.next();
					id = Integer.parseInt(u1.get("id").toString());
					server_pathname = u1.get("server_pathname").toString();
					// server_pathname =
					// "C:\\Users\\Shu\\Desktop\\eclipse-jee-mars-1-win32-x86_64\\eclipse\\寻访记录";
					// id = Integer.parseInt(u.get(0).toString());
					// server_pathname = u.get(1).toString();
					original_filename = u2.get("original_filename").toString();
					server_pathname = server_pathname + File.separator + original_filename;
					// server_pathname = server_pathname + "\\" +
					// original_filename;
					if (server_pathname.endsWith("xls") || server_pathname.endsWith("xlsx")) {
						System.out.println("=========解析寻访记录=========");
						parseExcelRecord(id, server_pathname, null, dao_record);
					}
					if (count % 1000 == 0) {
						session_record.commit();
						count = 0;
					}
				}
			}
			session_record.commit();
			try {
				Thread.sleep(10000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			} finally {
				session_record.close();
				session_record = null;
			}
		}
	}

	// 解析公司list
	public static void parseListBehind() throws IOException {
		// 解析联系人
		int id = 0;
		String server_pathname = "";
		String original_filename = "";
		int ownerid = 0;
		int companyid = 0;
		int count = 0;
		String resource = "MyBatis-Configuration.xml";
		Reader reader = null;
		try {
			reader = Resources.getResourceAsReader(resource);
		} catch (IOException e) {
			e.printStackTrace();
		}
		SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
		SqlSessionFactory factory = builder.build(reader);
		while (true) {
			SqlSession session_contact = factory.openSession();
			IDatabaseDao dao_contact = session_contact.getMapper(IDatabaseDao.class);
			// System.out.println("count"+count);
			List<Map> files_contact1 = dao_contact.queryContact1();
			List<Map> files_contact2 = dao_contact.queryContact2();
			if (files_contact1 != null && files_contact2 != null) {
				Iterator<Map> iter1 = files_contact1.iterator();
				Iterator<Map> iter2 = files_contact2.iterator();
				while (iter1.hasNext() && iter2.hasNext()) {
					count++;
					Map u1 = iter1.next();
					Map u2 = iter2.next();
					id = Integer.parseInt(u1.get("id").toString());
					server_pathname = u1.get("server_pathname").toString();
					// server_pathname = "C:\\Users\\Shu\\Desktop";
					// id = Integer.parseInt(u.get(0).toString());
					// server_pathname = u.get(1).toString();
					// ownerid = Integer.parseInt(u.get(2).toString());
					// original_filename = u.get(3).toString();
					ownerid = Integer.parseInt(u2.get("ownerid").toString());
					System.out.println("ownerid = " + ownerid);
					original_filename = u2.get("original_filename").toString();
					server_pathname = server_pathname + File.separator + original_filename;
					// server_pathname = server_pathname + "\\" +
					// original_filename;
					companyid = dao_contact.queryCompanyId(ownerid);
					System.out.println("companyid = " + companyid);
					if (server_pathname.endsWith("xls") || server_pathname.endsWith("xlsx")) {
						System.out.println("=========解析联系人=========");
						parseExcelContact(id, ownerid, companyid, server_pathname, null, dao_contact);
					} else {
						System.out.println("=========解析联系人csv=========");
						parseCSVContact(id, ownerid, companyid, server_pathname, null, dao_contact);
					}
					if (count % 1000 == 0) {
						session_contact.commit();
						count = 0;
					}
				}
			}
			session_contact.commit();
			try {
				Thread.sleep(10000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			} finally {
				session_contact.close();
				session_contact = null;
			}
		}
	}

}
